<template>
  <div class="comment">
    <slot name="header"></slot>
    <div class="comment__content">
      <div class="comment__content__tip" v-if="!this.loginState">
        登陆后可以发表评论 <span @click="userLogin" class="comment__content__tip__login">登陆</span>
      </div>
      <textarea
        :style="'width:' + commentWidth + 'px'"
        class="comment__content__textarea"
        :disabled="!loginState"
        placeholder="请输入评论内容...."
        v-model="comment"
      >
      </textarea>
    </div>
    <div class="comment__button" :style="'margin-top:' + buttonTop + 'px'">
      <div :class="comment ? 'comment__button__content--active' : 'comment__button__content--disabled'">发布</div>
    </div>
  </div>
</template>
<script>
import { mapState, mapActions } from "vuex";
export default {
  name: "Comment",
  computed: {
    ...mapState(["loginState"])
  },
  props: {
    //评论框长度
    commentWidth: {
      type: Number,
      default: 736
    },
    buttonTop: {
      type: Number,
      default: 20
    }
  },
  data() {
    return {
      comment: ""
    };
  },
  methods: {
    ...mapActions(["login"]),
    userLogin() {
      this.login({
        name: "蜡笔小新",
        msgNum: 8
      });
    }
  }
};
</script>
<style scoped lang="scss">
@mixin button($color) {
  position: absolute;
  right: 0;
  width: 120px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 20px;
  background: $color;
  color: #ffffff;
  cursor: pointer;
}
.comment {
  .comment__content {
    position: relative;
    &__textarea {
      font-family: SourceHanSansSC;
      font-size: 14px;
      color: #000001;
      font-weight: 400;
      margin: 16px 0;
      border: 1px solid rgba(0, 0, 0, 0.1);
      border-radius: 16px;
      height: 120px;
      padding: 10px;
    }
    &__textarea:focus {
      outline: none;
      border: 2px solid $color-royole;
    }
    &__tip {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      font-size: 16px;
      &__login {
        color: $color-royole;
        cursor: pointer;
        padding-left: 5px;
      }
    }
  }
  .comment__button {
    position: relative;
    margin-top: 20px;
    height: 40px;
    .comment__button__content--disabled {
      @include button(rgba(0, 80, 255, 0.1));
    }
    .comment__button__content--active {
      @include button(rgb(0, 80, 255));
    }
  }
}
</style>
